<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>药品分类列表</title>
    <link rel="shortcut icon" href="#" />
    <meta name="renderer" content="
    webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui-v2.5.6/css/layui.css" media="all">

    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

    <div class="layui-form-item">

        <div class="layui-inline">
            <label class="layui-form-label">药品名称：</label>
            <div class="layui-input-inline">
                <input type="text" name="typeName" id="typeName" placeholder="请输药品名称" autocomplete="off" class="layui-input">
            </div>
        </div>


    </div>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!--<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
        <!--<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
        <!--<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
        <button class="layui-btn layui-btn-sm" id="add" onclick="add()" lay-event="add">增加</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

</script>

<script crossorigin="anonymous" integrity="sha384-AQhQSZGQWTMJhb/TdS7NWpCmOM/8lIEsaevSU5oZtt8pQKoa+uJL4A2WnQ0O5Zj2" src="https://lib.baomitu.com/jquery/3.5.0/jquery.js"></script>

<script src="../../../res/layui-v2.5.6/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script src="../../../res/js/jquery-3.4.1.js" charset="utf-8"></script>
    <script src="/ok-admin/js/treeGrid.js"></script>
<script>
    var openindex=null;
    var table=null;
    var treeGrid=null;
    var editObj=null,ptable=null,treeGrid=null,tableId='test',layer=null;
    layui.config({
        base: '/ok-admin/js/'
    }).extend({
        treeGrid:'treeGrid'
    }).use(['jquery','treeGrid','layer','table','form'], function(){
        var $=layui.jquery;
        treeGrid = layui.treeGrid;//很重要
        layer=layui.layer;
        form  = layui.form;
        table = layui.table;
        treeGrid.render({
            id:tableId
            ,elem: '#'+tableId
            ,idField:'typeId'//必須字段
            ,treeId:'typeId'//树形id字段名称
            ,treeUpId:'yidTypeId2'//树形父id字段名称
            ,treeShowName:'typeName'//以树形式显示的字段
            ,isOpenDefault:true//节点默认是展开还是折叠【默认展开】
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,url: '/hqDrugtype/findAll' //数据接口
            ,method:'post'
            ,height:'100%'
            ,isFilter:false
            ,iconOpen:true//是否显示图标【默认显示】
            ,loading:true
            ,isPage:false
            ,cols: [[ //表头
                {type:'checkbox', fixed: 'left'},
                {field:  'typeNames', title: '上级类型', width:120, fixed: 'left'}
                ,{field: 'typeName', title: '材料类型名称' }
                ,{fixed: 'right',title: '操作', width: 225, align:'center', toolbar: '#barDemo'}
            ]]
            ,id: 'testReload'
        });

        //头工具栏事件
        treeGrid.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'add':
                    openIndex=layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['640px', '600px'], //宽高
                        content: 'Insert.html'
                    });
                    break;

                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        treeGrid.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    var url = "../../../hqDrugtype/deleteById";
                    console.info(data.typeId);
                    var datas = {typeId:data.typeId};
                    $.post(url,datas,function (objj) {
                        if (objj.status > 0){

                            layer.msg(objj.message);
                            treeGrid.reload('testReload');
                        }
                        layer.close(index);
                    },"json")
                });
            } else if(obj.event === 'edit'){
                var id =data.typeId;
                openIndex=layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['440px', '400px'], //宽高
                    content: 'Insert.html?id='+id
                });
            } else if(obj.event === 'add'){
                layer.prompt({
                    formType: 2
                    ,value: data.email
                }, function(value, index){
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            }
        });
        form.on('select(yidTypeId2)',function (data) {
            var s = data.value();
            table.reload('testReload',{
                where:{
                    yidTypeId2:s
                }
            })
        })

        form.on("submit(test)", function (data) {

            return false;
        });
        $('#typeName').bind('input propertychange', function() {

            var typeName = $('#typeName');
            //执行重载

            treeGrid.reload('testReload', {

                where: {
                    typeName: typeName.val()

                }
            });


        });

    });

    $(function () {

    });
    function add(){
        openIndex=layer.open({
            type: 2,
            skin: 'layui-layer-rim', //加上边框
            area: ['600px', '550px'], //宽高
            content: 'Insert.html'
        });

    }


</script>

</body>
</html>
